package com.qf.controller;

import com.qf.pojo.Clazz;
import com.qf.service.ClazzService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    ClazzService clazzService;

    /**
     * 全查所有班级
     * @return
     */
    @RequestMapping("/selectAll")
    public ResultMsg selectAll(@RequestParam(name = "page",defaultValue = "1",required = false) Integer page, @RequestParam(name = "limit",defaultValue = "10",required = false) Integer limit){
        return clazzService.selectAll(page,limit);
    }

    /**
     * 查询一个班级
     * @param clazzId
     * @return
     */
    @RequestMapping("/selectOne")
    public ResultMsg selectOne(Integer clazzId){
        return clazzService.selectOne(clazzId);
    }

    /**
     * 修改班级信息
     * @param clazz
     * @return
     */
//    @RequestMapping("/changeClazz")
    @PutMapping("/changeClazz")
    public ResultMsg changeClazz(@RequestBody Clazz clazz){
        return clazzService.changeClazz(clazz);
    }

    /**
     * 删除一个班级
     * @param clazzId
     * @return
     */
    @RequestMapping("/deleteOne")
    public ResultMsg deleteOne(Integer clazzId){
        return clazzService.deleteOne(clazzId);
    }

    /**
     * 批量删除班级
     * @param map
     * @return
     */
    @RequestMapping("deleteClazz")
    public ResultMsg deleteClazz(@RequestBody Map<String, List<Integer>> map){
        return clazzService.deleteClazz(map.get("clazzId"));
    }

    /**
     * 新增一个班级
     * @param clazz
     * @return
     */
//    @RequestMapping("/addClazz")
    @PutMapping("/addClazz")
    public ResultMsg addClazz(@RequestBody Clazz clazz){
        return clazzService.addClazz(clazz);
    }

    /**
     * 根据姓名和状态模糊查询
     * @param name
     * @param status
     * @return
     */
    @RequestMapping("/find")
    public ResultMsg find(String name,String status){
        return clazzService.find(name,status);
    }

    /**
     * 修改班级状态
     * @param clazzId
     * @return
     */
    @RequestMapping("/changeClazzStatus")
    public ResultMsg changeClazzStatus(Integer clazzId){
        return clazzService.changeClazzStatus(clazzId);
    }
}
